#pragma once
#include <locale.h>
#include <ncursesw/ncurses.h>
#include <ncurses.h>
#include <stdlib.h>
#include "Mylist.h"
#include "Myvector.h"
#include <unistd.h>
#include <time.h>

#define MENU_LINES 14
#define MENU_COLS  30
#define MAP_LINES1 16
#define MAP_COLS1  32
#define MAP_LINES2 24
#define MAP_COLS2  60
#define MAP_LINES3 28
#define MAP_COLS3  90

#define SETTING_LINES  14
#define SETTING_COLS  70

#define RESULT_LINES  7
#define RESULT_COLS  70
#define BUFFERSIZE 75

#define GET_MAPLEN(x) (x == 0 ? MAP_LINES1 : (x == 1 ? MAP_LINES2 : MAP_LINES3))
#define GET_MAPWID(x) (x == 0 ? MAP_COLS1 : (x == 1 ? MAP_COLS2 : MAP_COLS3))
#define GET_MAPPOS(x) (x == MAP_LINES1 ? 0 : (x == MAP_LINES2 ? 1 : 2))
#define GET_SPEEDPOS(x) (x == GAME_SPEED1 ? 0 : (x == GAME_SPEED2 ? 1 : 2))

#define GAME_SPEED1  400000
#define GAME_SPEED2  200000
#define GAME_SPEED3  150000
#define GET_SPEED(x) (x == 0 ? GAME_SPEED1 : (x == 1 ? GAME_SPEED2 : GAME_SPEED3))
#define ENTRE '\n'
#define SPACE ' '
#define NAP L"★"
#define FROMINPUT(x) do{ \
    if( x != 'w' && x != 'W' && x != KEY_UP && \
        x != 's' && x != 'S' && x != KEY_DOWN && \
        x != 'a' && x != 'A' && x != KEY_LEFT && \
        x != 'd' && x != 'D' && x != KEY_RIGHT && \
        x != ' ' && x != '\n'&& x != ENTRE) x = ERR; \
    if(x == 'w' || x == 'W') x = KEY_UP; \
    else if(x == 'a' || x == 'A') x = KEY_LEFT; \
    else if(x == 's' || x == 'S') x = KEY_DOWN; \
    else if(x == 'd' || x == 'D') x = KEY_RIGHT;}while(0)





typedef enum DIR{SUP, SDOWN, SLEFT, SRIGHT}DIR;


typedef struct Gamecolor{
	int snahead;
    int snaphy;
    int headcol;
    int phycol;
}Gacolor;

typedef struct GameAttribute{
	int maplength;
    int mapwidth;
    Gacolor color;
    int speed;
}GameAtt;

typedef struct Snake{
	List* physics;
    DIR dire;
    int score;
}Snake;


void Init();
int ShowMenu(int option);
void RunOption(int option);
void Game();
void HistoryScores();
void Setting();
void End();
void InitAttribute(GameAtt* att);
void InitResult(vector* allgameresult);
Snake* GetSnake();
void DestroySnake(Snake* sna);
void SnakeMove(Snake* sna, WINDOW* scrgame, WINDOW* scrscore);

